define([
     'u/common/app'
	],function(){
	 (function(){
	window.tab_load=Class.extend({
		init:function(params) {
            var self = this;
            this.ele = params.ele;
			this.tabli = params.tabli;
			this.box = params.box;
			this.boxcur = params.boxcur;
			this.current = params.current;
			this.success = params.success;
			self.start();
			if(typeof self.Operating=="function"){
				self.Operating()
			}
        },
		start:function() {
			var self = this;
			 //切换异步加载
				$(self.ele).each(function(index, element) {
					var o=$(this);
					var tab_li=o.find(self.tabli);
					var tabli=o.find(self.current);
					
					var box=$(self.box)
					tab_li.on("click",function(){
						 var li=$(this).index()
						 tab_li.removeClass("cur");
						 $(this).addClass("cur");
						 box.removeClass("cur")
						 box.eq(li).addClass("cur");
						 var url=$(this).attr("data-url");
						$("img[lazyload]").scrollLoading()
						 var type=$(this).attr("type")
						 var page=parseInt($(this).attr("data-page"))
						 if(page==1){
							 $(self.boxcur).addClass("on");
							 $.ajax({
										type: "get",
										url: url,
										data:{page:page,type:type},
										dataType: "json",
										success: function(e) {
											if(typeof self.success=="function"){
												self.success(e,page)
											
											}
											setTimeout(function(){$(self.boxcur).removeClass("on")},500);
											
										},
										error: function(XMLHttpRequest, textStatus, errorThrown) {
											alert(errorThrown);
										}
								});
						 }
						 $("img[lazyload]").scrollLoading()
					})
					$(tab_li).eq(0).click()
					$("img[lazyload]").scrollLoading()
					autoMore()
					function autoMore(){
					      var scLock = true;
						  $(window).bind('scroll', function() {
							var tabli=o.find(self.current)
							var page=parseInt(tabli.attr("data-page"))
							var box=$(self.boxcur)
							var type=tabli.attr("type");
							var url=tabli.attr("data-url");
							if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
								if (page>1&&scLock==true) {
									 scLock = false;
									$.ajax({
										type: "get",
										url: url,
										data:{page:page,type:type},
										dataType: "json",
										success: function(e) {
											$(box).addClass("on");
											if(typeof self.success=="function"){
												self.success(e,page)
											}
											setTimeout(function(){ scLock = true;},500);
										},
										error: function(XMLHttpRequest, textStatus, errorThrown) {
											alert(errorThrown);
										}
									});
								}
						
							}				 
						 });
					}
			   });
			   
		 }
		
	})
})()	
})
